<template>
  <div class="flex flex-col h-full">
    <SearchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="form-style-flex" :model="formState" :label-col="{ style: { width: '70px' } }">
        <a-form-item name="pyjm" label="" class="w-72">
          <a-input v-model:value="formState.pyjm" placeholder="处置名称/助记码" allow-clear />
        </a-form-item>
        <a-form-item name="dateRange" label="执行日期" class="w-80 ml-4">
          <a-range-picker v-model:value="formState['dateRange']" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <BaseTable fill :loading="loading" column-code="000496" :data-source="tableData" bordered :pagination="pagination">
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'mc'">
            <MedicineInfo :value="{ mc: record.mc, gg: record.gg }" />
          </template>
          <template v-if="column.dataIndex === 'action'">
            <a-button type="link" size="small" @click="openDetail(record)"> 明细 </a-button>
          </template>
        </template>
      </BaseTable>
    </a-card>
    <Detail v-model:open="detailOpen" :row-data="rowData" />
  </div>
</template>

<script setup>
import { ref, onMounted, reactive } from 'vue'
import dayjs from 'dayjs'
import SearchContainer from '@/components/SearchContainer'
import Detail from './Detail'

const formRef = ref(null)
const formState = reactive({
  dateRange: [dayjs().subtract(20, 'day').format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')],
  pyjm: ''
})
const detailOpen = ref(false)
const rowData = ref({})

const { loading, tableData, pagination, getData } = useTable({
  url: '/outp/outpComprehensive/getDispositionStatistics',
  formatParams: () => {
    return {
      stdate: formState.dateRange?.[0],
      eddate: formState.dateRange?.[1],
      pyjm: formState.pyjm
    }
  }
})

const openDetail = async (row) => {
  detailOpen.value = true
  rowData.value = { ...row, stdate: formState.dateRange?.[0], eddate: formState.dateRange?.[1] }
}

onMounted(() => {
  getData()
})
</script>
<style lang="less" scoped>
.ant-picker {
  width: 100%;
}
</style>
